package com.hspedu.map_;

import java.util.Properties;

/**
 * @author DL5O
 * @version 1.0
 */
public class Properties_ {
    public static void main(String[] args) {
        //1. Properties 继承了 HashTable
        //2. 可以通过k-v来存放数据，当然key 和 value 不能为空
        //增加
        Properties properties = new Properties();
        properties.put("john",100);
//        properties.put(null,100);
//        NullPointerException 空指针异常，键是不能为空的

//        properties.put("john",null);
        //空指针异常，value值也不能为空
        properties.put("lucy",100);
        properties.put("lic",100);
        properties.put("lic",88);//如果有相同的key，那么值就会被替换
        System.out.println(properties);
        //{lic=88, john=100, lucy=100}

        //如何通过key获取对应的值
        System.out.println(properties.get("lic"));//88

        //删除元素
        properties.remove("lic");
        System.out.println(properties);//{john=100, lucy=100}

        //修改
        properties.put("john","约翰");
        System.out.println(properties);

        //查找
        System.out.println(properties.get("john"));//约翰
        System.out.println(properties.getProperty("john"));//约翰

    }
}
